package com.morizhang.merchanmanager.api.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.morizhang.merchanmanager.api.ApiResult;
import com.morizhang.merchanmanager.api.IService;
import com.morizhang.merchanmanager.api.model.CommodityDataModel;
import com.morizhang.merchanmanager.api.plugins.BasicWareManage;

@ServiceAnnotation(name = "QueryCommodityInfo")
public class QueryCommodityInfoService implements IService {

    private final BasicWareManage basicWareManager;

    public QueryCommodityInfoService(BasicWareManage basicWareManager) {
        this.basicWareManager = basicWareManager;
    }

    @Override
    public ApiResult callService(JSONObject requestParams) throws Exception {
        String barCode = requestParams.getJSONObject("data").getString("barCode");
        CommodityDataModel modelResult = basicWareManager.queryCommodity(barCode);
        ApiResult result = new ApiResult();
        result.setData(JSON.parseObject(JSON.toJSONString(modelResult)));
        result.setSuccess(true);
        return result;
    }
}
